package com.drp.service.impl;

import com.drp.bean.Goods;
import com.drp.bean.Kind;
import com.drp.bean.Supplier;
import com.drp.bean.User;
import com.drp.controller.SupplierController;
import com.drp.dao.GoodsMapper;
import com.drp.dao.KindMapper;
import com.drp.dao.SupplierMapper;
import com.drp.dao.UserMapper;
import com.drp.service.IGoodsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.drp.vo.GoodsVo;
import com.drp.vo.ResultGoodVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ren
 * @since 2022-03-16
 */
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements IGoodsService {
    @Autowired
    @Qualifier("goodsMapper")
    private GoodsMapper goodsMapper;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private KindMapper kindMapper;
    @Autowired
    private SupplierMapper supplierMapper;
    @Override
    public boolean add(Goods goods, User user, Kind kind, Supplier supplier) {
        userMapper.insert(user);
        goods.setFkUserid(user.getUId());
        kindMapper.insert(kind);
        goods.setFkKindid(kind.getKId());
        supplierMapper.insert(supplier);
        goods.setFkSupplierid(user.getUId());
        goodsMapper.add(goods);
        return true;
    }

    @Override
    public List<Goods> getAll() {
        return goodsMapper.getAll();
    }

    @Override
    public boolean deleteById(int id) {
        int i = goodsMapper.deleteById(id);
        return i>=1?true:false;

    }

    @Override
    public int addGood(Goods goods) {
        return goodsMapper.addGood(goods);
    }
}
